#version 400

layout (location = 0) out vec4 fragment_color;

uniform ivec2 framebuffer_size;
uniform ivec2 source;
uniform ivec2 destination;

void main()
{
	vec2 s = source / float(framebuffer_size);
	vec2 d = destination / float(framebuffer_size);
	vec2 f = gl_FragCoord.xy / float(framebuffer_size);
	vec2 direction = s - d;

	float distance_to_destination = length(d - s);
	float distance_from_source = length(f - s);
	
	if (distance_from_source <= distance_to_destination)
	{
		float displacement = 0;

		if (distance_from_source == 0)
		{
			displacement = distance_to_destination;
		}
		else
		{
			displacement = distance_to_destination - distance_from_source;
		}

		fragment_color = vec4(displacement, displacement, displacement, 1);
	}
	else
	{
		fragment_color = vec4(0, 0, 0, 1);
	}
}